<template>
  <div style="margin-top:20px">
    <el-form ref="form" label-width="80px" :model="form">
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="标题" style="margin-right:15px">
              <el-input v-model="form.title" :disabled="true" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="副标题" style="margin-right:15px">
              <el-input type="textarea" :rows="3" v-model="form.subhead" :disabled="true" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="编辑者" style="margin-right:15px">
              <el-input v-model="form.editName" :disabled="true" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="类别" style="margin-right:15px">
              <el-select v-model="form.newsType" :disabled="true">
                <el-option
                  v-for="(v,k) in dicts.newsType"
                  :key="k"
                  :label="v"
                  :value="k"
                />
              </el-select>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="图片" style="margin-right:15px">
              <img v-if="form.imgUrl" :src="form.imgUrl" class="el-upload-list__item-thumbnail" width="100%" height="100%">
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="新闻内容" prop="content" style="margin-right:15px">
              <myEditor ref="editor" v-model="form.content" :disabled="true" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import Vue from 'vue'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
import request from '@/utils/request'
import myEditor from '@/components/MyEditor'
Vue.use(VXETable)
export default {
  name: 'NewsDetail',
  components: {
    myEditor
  },
  data() {
    return {
      dicts: { isRelease: {}, newsType: {}},
      emptyForm: {},
      form: {
        imgUrl: '',
        title: '',
        content: '',
        editName: '',
        newsType: '',
        ifRelease: '0'
      }
    }
  },
  created() {
    // 保存空表单对象
    this.emptyForm = JSON.parse(JSON.stringify(this.form))
  },
  methods: {
    // 获取页面信息
    getInfo(code, dicts) {
      this.dicts = dicts
      // 查询到数据之前先展示空表单
      this.form = JSON.parse(JSON.stringify(this.emptyForm))
      request({ url: `/arpa-basic-api/news/${code}`, method: 'get' }).then(response => {
        this.form = response.data
      })
    }
  }
}
</script>
<style lang="scss" scoped>
  .dialog-footer {
    margin-top: 50px;
  }
</style>
